<?php
class SignAction extends Action {
	public function index($userid)
	{

        file_put_contents("log.txt","进入签到".PHP_EOL,FILE_APPEND);

		$info = M('Qyusers_ur')->where(array('userid'=>$userid))->find();
		if($info){
			return $this->handle($info);
		}else{
			 return "签到失败";
		}
		exit;


	}

   // 处理签到业务

    public function handle($info){


    	if($info['status']!=1){
		    	$data['status'] = 1;
		    	$data['ctime'] =time();
		        D('Qyusers_ur')->where('userid='.$info['userid'])->save($data);
				file_put_contents("log.txt",M()->getLastSql().PHP_EOL,FILE_APPEND);

				return "亲爱的".$info['name']."同事，欢迎您出席UR焕变年度盛典，您的座桌是".$info['num']."号";

	    }else{

	    	return "您已经签到过了，您的座桌是".$info['num']."号，UR焕变年度盛典欢迎您!";
	    }


    }

	/******响应消息类型****/
	//text消息
	public function text($data){
		$str=
		"<xml>
		   <ToUserName><![CDATA[".$data['reqFromUserName']."]]></ToUserName>
		   <FromUserName><![CDATA[".$data['corpId']."]]></FromUserName>
		   <CreateTime>".$data['sReqTimeStamp']."</CreateTime>
		   <MsgType><![CDATA[text]]></MsgType>
		   <Content><![CDATA[".$data['content']."]]></Content>
		</xml>";
		return $str;
	}

	//image消息
	public function image($data){
		$str=
		"<xml>
		   <ToUserName><![CDATA[toUser]]></ToUserName>
		   <FromUserName><![CDATA[fromUser]]></FromUserName>
		   <CreateTime>1348831860</CreateTime>
		   <MsgType><![CDATA[image]]></MsgType>
		   <Image>
			   <MediaId><![CDATA[media_id]]></MediaId>
		   </Image>
		</xml>";
		return $str;
	}

	//news
	public function news_one($data){
		$str=
			"<xml>
   <ToUserName><![CDATA[".$data['reqFromUserName']."]]></ToUserName>
   <FromUserName><![CDATA[".$data['corpId']."]]></FromUserName>
   <CreateTime>".$data['sReqTimeStamp']."</CreateTime>
   <MsgType><![CDATA[news]]></MsgType>
   <ArticleCount>1</ArticleCount>
   <Articles>
       <item>
           <Title><![CDATA[".$data['title']."]]></Title>
           <Description><![CDATA[".$data['description']."]]></Description>
           <PicUrl><![CDATA[".$data['picurl']."]]></PicUrl>
           <Url><![CDATA[".$data['url']."]]></Url>
       </item>
   </Articles>
</xml>";

	return $str;
	}



	//
	function curlGet($url){
		$ch = curl_init();
		$header = "Accept-Charset: utf-8";
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		$temp = curl_exec($ch);
		return $temp;
	}



}
?>